﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Data;

public partial class per_me_tanchu : System.Web.UI.Page
{
    protected int id = ReadRequest.RequestInt("id");
    protected int userCount = 0;
    protected int userMoney = 0;
    protected List<Model.LotteryChippedUser> dt = null;
    protected string primaryKey = "id";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    public List<Model.LotteryChippedUser> GetPageList_Where(int PageIndex, int PageSize, string sql, out int totalCount)
    {
        totalCount = new DataAccess().GetCount<Model.LotteryChippedUser>(primaryKey, sql);
        return new DataAccess().GetPage_List<Model.LotteryChippedUser>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);
    }
    protected void Bind()
    {
        int totalCount = 0;
        //dt = BLL.Documentary.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, " LotteryChippedid='" + id + "'", out totalCount);
        dt = GetPageList_Where(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, " LotteryChippedID='" + id + "'", out totalCount);
        userCount = totalCount;
        Model.LotteryChipped model = BLL.LotteryChipped.GetModel(id);
        decimal money = model.LotteryMoney - model.MySub;
        if (userCount > 0)
        {
            userMoney = (int)money / userCount;
        }
        PagedDataSource pds = new PagedDataSource();
        if (dt != null && dt.Count > 0)
        {

            AspNetPager1.RecordCount = dt.Count;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    public string getUserName(object id)
    {
        return BLL.CMember.GetModel(long.Parse(id.ToString())).nickname;
    }
    protected void serachBtn_Click(object sender, EventArgs e)
    {
        Model.CMember model = BLL.CMember.GetOneBynickname(userNametxt.Text);
        if (model != null && model.Id > 0)
        {
            int total = 0;
            // dt = BLL.Documentary.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, "LotteryChippedid='" + id + "' and user_id=" + model.Id, out total);
            dt = GetPageList_Where(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, " LotteryChippedID='" + id + "'and UserID=" + model.Id, out total);
            userCount = total;
            userMoney = int.Parse(dt[0].MySub.ToString());

        }
        if (userNametxt.Text == "")
        {
            Bind();
        }
        PagedDataSource pds = new PagedDataSource();
        if (dt != null && dt.Count > 0)
        {

            AspNetPager1.RecordCount = dt.Count;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
    }
}